<!-- 二维码识别 -->
<template>
  <div>
    <button @click="clickbwipjs">bwip-js二维码</button>
    <br />
    <br />
    <canvas id="barcodeCanvas"></canvas>
  </div>
</template>

<script>
import bwipjs from "bwip-js";
export default {
  name: "Datamatrix",
  props: {
    barCodeLength: {
      type: Number,
      default: 7,
    },
    barCodeInfo: {
      type: String,
      default: "",
    },
    barCodeType:{
      type:String,
      default:"",
    }
  },
  data() {
    return {
      barCodeTextInfo:"asd;flkjasdf",
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods: {
    clickbwipjs() {
      console.log("clickbwipjs");
      if (this.barCodeInfo == "") {
        console.log("无二维码信息");
      }
      try {
        // The return value is the canvas element
        let mycanvas = bwipjs.toCanvas("barcodeCanvas", {
          bcid: this.barCodeType, // Barcode type
          text: this.barCodeInfo, // Text to encode
          scale: 2, // 3x scaling factor
          height: this.barCodeLength, // Bar height, in millimeters
          width: this.barCodeLength,
          includetext: false, // Show human-readable text
          textxalign: "center", // Always good to set this
        });
        console.log(mycanvas);
      } catch (e) {
        // `e` may be a string or Error object
      }
    },
  },
};
</script>
<style scoped>
/* @import url(); 引入css类 */
</style>